package com.wuniutech.notebook

import android.annotation.SuppressLint
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.provider.Settings
import android.telephony.TelephonyManager

/**
 * Created by ZCY on 2019-07-05 15:52
 */
object DeviceUtils {

    /**
     * 获取设备唯一标识
     */
    @SuppressLint("HardwareIds")
    fun getAndroidID(): String {
        return Settings.Secure.getString(AppContext.getContext().contentResolver,
            Settings.Secure.ANDROID_ID)
    }

    /**
     * 获取手机品牌和型号
     */
    fun getDeviceModel(): String {
        val brand = android.os.Build.BRAND
        val model = android.os.Build.MODEL
        return "$brand-$model"
    }

    /**
     * 获取应用版本名字
     */
    fun getVersionName(): String? {
        return AppContext.getContext().packageManager.getPackageInfo(AppContext.getContext().packageName,
            0).versionName
    }

    /**
     * 获取应用版本号
     */
    fun getVersionCode(): Int {
        return AppContext.getContext().packageManager.getPackageInfo(AppContext.getContext().packageName,
            0).versionCode
    }

    /**
     * 获取iccid
     */
    @SuppressLint("HardwareIds")
    fun getSimICCId(context: Context): String? {
        val tManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
        return tManager.simSerialNumber
    }

    /**
     * Copies the given text to the Android clipboard.
     *
     * @param context The context (e.g., Activity)
     * @param label   A label for the clip data (optional, but good practice)
     * @param text    The text to copy
     */
    fun copyTextToClipboard(context: Context,
        label: String,
        text: String) { // Get the system clipboard manager
        val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager

        // Create a new ClipData object.
        // ClipData represents an item on the clipboard.
        // newPlainText creates a new ClipData holding plain text.
        // The first argument is a user-visible label for the data.
        // The second argument is the actual text data.
        val clip = ClipData.newPlainText(label, text)

        // Set the clip data to the clipboard.
        // This makes the text available for pasting in other applications.
        clipboard.setPrimaryClip(clip) // Optionally, show a Toast message to confirm the copy action to the user.
    }
}